<?php

class ContactUs extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);

		if (!$this->IsPostBack)
		{
			$this->Master->pageHead->Title = $this->Application->Parameters["WEBSITE_TITLE"]." - Contact Us";

			if ($this->Request->contains('m') && $this->Request['m'] == 'ctu') {
				$this->Notice->Type = UserNoticeType::Notice;
				$this->Notice->Text = "Thank you! We've received your message and will reply to you soon.";
			}
		}

	}
	
	protected function btnSubmit_Clicked($sender, $param)
	{
		if ($this->IsValid)
		{			
			$emailer = $this->Application->getModule('mailer');
			$email = $emailer->createNewEmail("ContactUs");
			$email->HtmlContent->findControl("CONTACT_NAME")->Text = $this->txtName->SafeText;
			$email->HtmlContent->findControl("CONTACT_EMAIL")->Text = $this->txtEmail->SafeText;
			$email->HtmlContent->findControl("SUBJECT")->Text = $this->txtSubject->SafeText;
			$email->HtmlContent->findControl("MESSAGE")->Text = $this->txtMessage->SafeText;
			$receiver = new TEmailAddress;
			$receiver->Field = TEmailAddressField::Receiver;
			$receiver->Address = $this->Application->Parameters['CONTACTUS_EMAIL'];
			$receiver->Name = $this->Application->Parameters['CONTACTUS_NAME'];
			$email->getEmailAddresses()->add($receiver);
			$emailer->send($email);	
			
			$this->Response->redirect($this->Service->ConstructUrl("corp.ContactUs", array('m'=>'ctu')));
		}
	}
}

?>